import java.util.*;
public class Main2 {

    // 1. 枚举
    public static void main1(String[]args) {
        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()){
            String s1 = scanner.nextLine();
            String s2 = scanner.nextLine();

            longString(s1,s2);
        }
    }
    public static void longString(String s1,String s2){

        String shortStr = s1.length() < s2.length() ? s1 : s2;
        String longStr = s1.length() > s2.length() ? s1 : s2;

        int shortLen = shortStr.length();

        int maxLen = 0, start = 0;
        for(int i = 0; i < shortLen; i++) {
            // 当剩余的子串长度不超过maxLen时,退出循环
            if(shortLen - i + 1 <= maxLen) {
                break;
            }
            // 左指针i, 右指针k, 右指针逐渐向i逼近
            for(int k = shortLen; i < k; k--) {
                String subStr = shortStr.substring(i, k);
                if(longStr.contains(subStr) && maxLen < subStr.length()) {
                    maxLen = subStr.length();
                    start = i;
                    // 找到就立即返回 进行下一次匹配.
                    break;
                }
            }
        }
        System.out.println(shortStr.substring(start, start + maxLen));
    }

    // 2. dp
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String s1 = sc.nextLine();
            String s2 = sc.nextLine();
            System.out.println(longString2(s1,s2));
        }
    }

    // 动态规划
    public static String longString2(String str1, String str2) {
        String temp = "";
        // 保证str1是较短字符串
        if (str1.length() > str2.length()) {
            temp = str1;
            str1 = str2;
            str2 = temp;
        }

        int m = str1.length() + 1;
        int n = str2.length() + 1;
        // 表示在较短字符串str1以第i个字符结尾，str2中以第j个字符结尾时的公共子串长度。
        int[][] dp = new int[m][n];
        // 匹配字符，并记录最大值的str1的结尾下标
        int max = 0;
        int index = 0;
        // 从左向右递推，i为短字符串str1的结尾索引，j为str2的结尾索引
        for (int i = 1; i < m; i++) {
            for (int j = 1; j < n; j++) {
                if (str1.charAt(i-1) == str2.charAt(j-1)) {
                    // 相等则计数.
                    dp[i][j] = dp[i-1][j-1] + 1;
                    // 不断更新变量.
                    if (dp[i][j] > max) {
                        max = dp[i][j];
                        index = i;
                    }
                }
            }
        }
        // 截取最大公共子串
        return str1.substring(index-max, index);
    }
}
